package com.homework;

import java.util.Vector;

public class Tank {
    private int x;
    private int y;
    private int direction;
    private int speed = 10;
    boolean isLive = true;
    Vector shots = new Vector<>();
    public void moveUp() {
        if (getY() > 0)
            y -= speed;
    }

    public void moveRight() {
        if (getX() < 925)
            x += speed;
    }

    public void moveLeft() {
        if (getX() > 0)
            x -= speed;
    }

    public void moveDown() {
        if (getY() < 655)
            y += speed;
    }

    public Tank(int x, int y, int direction) {
        this.x = x;
        this.y = y;
        this.direction = direction;
    }

    public void newShot(Tank tank) {
        if(shots.size()<=5) {
            Shot shot = null;
            switch (getDirection()) {
                case 0:
                    shot = new Shot(getX() + 20, getY(), 0, tank);
                    break;
                case 1:
                    shot = new Shot(getX() + 60, getY() + 20, 1, tank);
                    break;
                case 2:
                    shot = new Shot(getX() + 20, getY() + 60, 2, tank);
                    break;
                case 3:
                    shot = new Shot(getX(), getY() + 20, 3, tank);
                    break;
            }
            shots.add(shot);
            new AudioPlayer("music/fire.wav").new AudioThread().start();
            new Thread(shot).start();
        }
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getDirection() {
        return direction;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }
}
